// +FHDR------------------------------------------------------------
//                 Copyright (c) 2024 NOVAUTO.
//                       ALL RIGHTS RESERVED
// -----------------------------------------------------------------
// Filename      : flow_cnt.sv
// Author        : ICer
// Created On    : 2024-01-04 15:38
// Last Modified : 2024-01-04 17:49 by ICer
// -----------------------------------------------------------------
// Description:
//
//
// -FHDR------------------------------------------------------------


module flow_cnt #(
  //parameter
  parameter realtime START_TIME = 0ns,
  parameter realtime END_TIME = -1ns, 
  parameter BIT_W  = 10, //max 1023bit per cycle
  parameter MAX_W  = 64  //bit cnt max
)( /*AUTOARG*/
   // Inputs
   clk, rst_n, power, bit_cnt
   );

// ----------------------------------------------------------------
// Interface declare
// ----------------------------------------------------------------
input              clk;
input              rst_n;
input              power;
input [BIT_W  -1:0]bit_cnt;

// ----------------------------------------------------------------
// Wire declare
// ----------------------------------------------------------------

// ----------------------------------------------------------------
// AUTO declare
// ----------------------------------------------------------------
/*AUTOOUTPUT*/
/*AUTOINPUT*/
/*AUTOWIRE*/

logic [MAX_W -1:0]whole_bit_cnt;

always @(posedge clk or negedge rst_n) begin
  if(!rst_n) begin
    whole_bit_cnt <= {MAX_W{1'b0}};
  end 
  else if($realtime>=START_TIME && ($realtime<END_TIME || END_TIME<=0)) begin
    if(power) 
      whole_bit_cnt <= whole_bit_cnt + bit_cnt;
  end 
end

initial begin: BANDWIDTH_REPORT
  real flow_bandwidth;
  realtime time_duration;
  while(1)begin
    @(posedge clk);
    if($realtime<END_TIME)begin
      continue;
    end
    else begin
      time_duration  = $realtime - START_TIME;
      flow_bandwidth = whole_bit_cnt/time_duration;
      $display("==============================================================================");
      $display("%m bandwidth report at %t:", $realtime);
      $display("    whole_bit_cnt = %0dbit = %0dByte", whole_bit_cnt, whole_bit_cnt/8);
      $display("    time_duration  = %t", time_duration);
      $display("    flow_bandwidth = %fGbps", flow_bandwidth);
      $display("==============================================================================");
      break;
    end
  end
end

endmodule
// Local Variables:
// verilog-auto-inst-param-value:t
// verilog-library-directories:(".")
// verilog-library-extensions:(".v")
// End:

